package com.fenghongzhang.day005test2.common;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitUtil {

    private static RetrofitUtil retrofitUtil = new RetrofitUtil();
    private RetrofitUtil(){
    }

    private  static final String BASE_URL = "http://49.233.0.68:8080/";
    public synchronized static RetrofitUtil getRetrofitUtil(){
        return retrofitUtil;
    }

    private  Retrofit retrofit;

    public synchronized  Retrofit getRetrofit(){
        if(retrofit == null){
            return  retrofit =  new Retrofit.Builder()
                    .client(new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build())
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .baseUrl(BASE_URL)
                    .build();
        }
        return retrofit;
    }

}
